# mode:shell-script # sh-shell:bash # Modified to work on Open Solaris. Much better than FreeBSD. # There are still problems with ls but I am working on that. # Bejiitas Wrath ~/.bashrc. [ -f /etc/bashrc ] && . /etc/bashrc [ -f /etc/profile ] && . /etc/profile if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi OSRELEASE=`uname -r`; PATH=$PATH:~/bin:/tools/bin # Author: John Cartwright. # Website: http://members.tripod.com/bejiitas_wrath/ # I am including many useful if statements in this # .bashrc so that if a needed program is not installed # it will still give some alternate output. # Setting a blinking block cursor for the console. # echo -e '\033[?6c' # try to set DISPLAY smart (from Hans) :) # From a SUSE .bashrc file. # if test -z "$DISPLAY" -a "$TERM" = "xterm" -a -x /usr/bin/who ; then WHOAMI="`/usr/bin/who am i`" _DISPLAY="`expr "$WHOAMI" : '.*(\([^\.][^\.]*\).*)'`:0.0" if [ "${_DISPLAY}" != ":0:0.0" -a "${_DISPLAY}" != " :0.0" \ -a "${_DISPLAY}" != ":0.0" ]; then export DISPLAY="${_DISPLAY}"; fi unset WHOAMI _DISPLAY fi export HISTCONTROL=ignoredups export EDITOR=ex export DOOMWADDIR="/home/goku/doom" # For doom! export TIME_STYLE=+" %d-%m-%y %I:%M %P" # These two examples from bash-doc. export PAGER="/usr/bin/less" export VIEWER="mcedit" export LESS="-i -e -M -P%t?f%f :stdin .?pb%pb\%:?lbLine %lb:?bbByte %bb:-..." shopt -s checkwinsize eval `dircolors -b` alias dir='ls --format="vertical"' alias vdir='ls --format="long"' alias verbosetree='tree -A -s -p -f --dirsfirst' alias psverbose='ps u a x f g' alias ll='ls -l | sort -nr' alias la='ls -A' alias l='ls -CF' alias dsize="du -ack | sort -nr | head -n 20" alias psview="pstree -a -u -G -l -h -p" # These following functions from # http://www.die.net/doc/linux/abs-guide/sample-bashrc.html function my_ip() # get IP adresses. Bracket on next line C style... { MY_IP=$(/sbin/ifconfig ppp0 | awk '/inet/ { print $2 } ' | sed -e s/addr://) MY_ISP=$(/sbin/ifconfig ppp0 | awk '/P-t-P/ { print $3 } ' | sed -e s/P-t-P://) } function lowercase() # move filenames to lowercase. { for file ; do filename=${file##*/} case "$filename" in */*) dirname==${file%/*} ;; *) dirname=.;; esac nf=$(echo $filename | tr A-Z a-z) newname="${dirname}/${nf}" if [ "$nf" != "$filename" ]; then mv "$file" "$newname" echo "lowercase: $file --> $newname" else echo "lowercase: $file not changed." fi done } function badlink() # From Atomic magazine #43 August 2004. http://www.atomicmpc.com.au { DEFAULT=$(tput sgr0); FILELIST=.badlink.list [ -e $FILELIST ] && $( rm -fr $FILELIST ) function checklink() { for badlink in $1/*; do [ -h "$badlink" -a ! -e "$badlink" ] && echo \ \"$badlink\" >> $FILELIST [ -d "$badlink" ] && checklink $badlink done } for directory in `pwd`; do if [ -d $directory ] ; then checklink $directory; fi done if [ -e $FILELIST ] ; then for line in $(cat $FILELIST); do echo $line | xargs -r rm | echo -e "$line \ -removed" echo done rm -fr $FILELIST else printf "Bad symlinks not found.\n\n" fi } # End Atomic function. function grephist() { grep $1 ~/.history/history } source cd_func.sh echo "On this day in the GNU/Linux epoch." echo /bin/grep "$(date +'%m/%d')" ~/bin/calendar.computer # Setting the value of the Xterm title. # Only if we are in X... if [ $DISPLAY ] ; then PROMPT_COMMAND='echo -ne "\033]0;${OSRELEASE}: ${PWD}\007"' fi if [ -x /usr/bin/finger ] ; then INFO=$(finger -lmps $LOGNAME | sed -e "s/On/Logged in/g" | grep "since" ) else INFO=$(uname -msov) fi #echo -ne "${INFO}\n" if [ $DISPLAY ] ; then # Testing for either xterm or rxvt or uxvt or uxterm... # etc. Works in a xterm on Open Solaris just fine... PS1='\n[ \e[041m\e[40m\e[37m\e[1m\u@${OSRELEASE}\e[41m\e[0m ]\n[ \ \e[033mJobs \j.\e[0m\e[30m\e[41m\e[1m\e[33mPWD: \w.\s \V.\e[0m ] [\e[4m \# \ \e[0m]\n[ \t ]\n[ \$ ]-> ' PS2='=> ' fi # Outside of X we use this! if [ "$TERM" == "linux" ]; then PS1='\e[31m\e[40m\e[37m\e[1m\u@${OSRELEASE}.\e[0m\n \e[30m\e[41m\e[1m \ \e[33mPWD\w.\e[0m \ \s.\n \V. \# \$> ' fi # Outside of xinit we use this! For Open Solaris. Which rules over FreeBSD Btw. if [ "$TERM" == "sun-color" ]; then PS1='\u@${OSRELEASE}.\n PWD: \w. \s.\n \V. \# \$> ' fi # The following code from http://www.die.net/doc/linux/abs-guide/sample-bashrc.html if [ "${BASH_VERSION%.*}" \< "2.05" ]; then echo "You will need to upgrade to version 2.05 for programmable completion" return fi shopt -s extglob # necessary set +o nounset # otherwise some completions will fail complete -A hostname rsh rcp telnet rlogin r ftp ping disk complete -A command nohup exec eval trace gdb complete -A command command type which complete -A export printenv complete -A variable export local readonly unset complete -A enabled builtin complete -A alias alias unalias complete -A function function complete -A user su mail finger complete -A helptopic help # currently same as builtins complete -A shopt shopt complete -A stopped -P '%' bg complete -A job -P '%' fg jobs disown complete -A directory mkdir rmdir complete -A directory -o default cd complete -f -d -X '*.gz' gzip complete -f -d -X '*.bz2' bzip2 complete -f -o default -X '!*.gz' gunzip complete -f -o default -X '!*.bz2' bunzip2 complete -f -o default -X '!*.pl' perl perl5 complete -f -o default -X '!*.ps' gs ghostview ps2pdf ps2ascii complete -f -o default -X '!*.dvi' dvips dvipdf xdvi dviselect dvitype complete -f -o default -X '!*.pdf' acroread pdf2ps complete -f -o default -X '!*.+(pdf|ps)' gv complete -f -o default -X '!*.texi*' makeinfo texi2dvi texi2html texi2pdf complete -f -o default -X '!*.tex' tex latex slitex complete -f -o default -X '!*.lyx' lyx complete -f -o default -X '!*.+(jpg|gif|xpm|png|bmp)' xv gimp complete -f -o default -X '!*.mp3' mpg123 complete -f -o default -X '!*.ogg' ogg123 #=====================================================================================# # This is a 'universal' completion function - it works when commands have # a so-called 'long options' mode , ie: 'ls --all' instead of 'ls -a' _universal_func () { case "$2" in -*) ;; *) return ;; esac case "$1" in \~*) eval cmd=$1 ;; *) cmd="$1" ;; esac COMPREPLY=( $("$cmd" --help | sed -e '/--/!d' -e 's/.*--\([^ ]*\).*/--\1/'| \ grep ^"$2" |sort -u) ) } complete -o default -F _universal_func ldd wget bash id info _make_targets () { local mdef makef gcmd cur prev i COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} # if prev argument is -f, return possible filename completions. # we could be a little smarter here and return matches against # `makefile Makefile *.mk', whatever exists case "$prev" in -*f) COMPREPLY=( $(compgen -f $cur ) ); return 0;; esac # if we want an option, return the possible posix options case "$cur" in -) COMPREPLY=(-e -f -i -k -n -p -q -r -S -s -t); return 0;; esac # make reads `makefile' before `Makefile' if [ -f makefile ]; then mdef=makefile elif [ -f Makefile ]; then mdef=Makefile else mdef=*.mk # local convention fi # before we scan for targets, see if a makefile name was specified # with -f for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do if [[ ${COMP_WORDS[i]} == -*f ]]; then eval makef=${COMP_WORDS[i+1]} # eval for tilde expansion break fi done [ -z "$makef" ] && makef=$mdef # if we have a partial word to complete, restrict completions to # matches of that word if [ -n "$2" ]; then gcmd='grep "^$2"' ; else gcmd=cat ; fi # if we don't want to use *.mk, we can take out the cat and use # test -f $makef and input redirection COMPREPLY=( $(cat $makef 2>/dev/null | awk 'BEGIN {FS=":"} /^[^.# ][^=]*:/ {print $1}' | tr -s ' ' '\012' | sort -u | eval $gcmd ) ) } complete -F _make_targets -X '+($*|*.[cho])' make gmake pmake _configure_func () { case "$2" in -*) ;; *) return ;; esac case "$1" in \~*) eval cmd=$1 ;; *) cmd="$1" ;; esac COMPREPLY=( $("$cmd" --help | awk '{if ($1 ~ /--.*/) print $1}' | grep ^"$2" | sort -u) ) } complete -F _configure_func configure # cvs(1) completion _cvs () { local cur prev COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} if [ $COMP_CWORD -eq 1 ] || [ "${prev:0:1}" = "-" ]; then COMPREPLY=( $( compgen -W 'add admin checkout commit diff \ export history import log rdiff release remove rtag status \ tag update' $cur )) else COMPREPLY=( $( compgen -f $cur )) fi return 0 } complete -F _cvs cvs _killall () { local cur prev COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} # get a list of processes (the first sed evaluation # takes care of swapped out processes, the second # takes care of getting the basename of the process) COMPREPLY=( $( /usr/bin/ps -u $USER -o comm | \ sed -e '1,1d' -e 's#[]\[]##g' -e 's#^.*/##'| \ awk '{if ($0 ~ /^'$cur'/) print $0}' )) return 0 } complete -F _killall killall killps # End: Bejiitas Wrath .bashrc.